package com.syz.mall.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sun.org.apache.xpath.internal.operations.Or;
import com.syz.mall.mapper.OrderMapper;
import com.syz.mall.pojo.Order;
import com.syz.mall.pojo.query.OrderQuery;
import com.syz.mall.pojo.vo.OrderEchartsVO;
import com.syz.mall.pojo.vo.OrderVO;
import com.syz.mall.service.IOrderService;
import com.syz.mall.util.LayUITableResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl implements IOrderService {
    @Autowired
    private OrderMapper orderMapper;

    @Override
    public LayUITableResult selectByPage(OrderQuery orderQuery) {
        //PageHelper.startPage(orderQuery.getPage(), orderQuery.getLimit());
        List<OrderVO> list = orderMapper.selectAllVO(orderQuery);
        //PageInfo pageInfo = new PageInfo(list);
        //long totalCount = pageInfo.getTotal();

        int totalCount=list.size();
        int page=orderQuery.getPage();
        int limit=orderQuery.getLimit();
        List<OrderVO> list2=list.subList(limit*(page-1),Math.min(limit*(page-1)+limit,totalCount));
        return LayUITableResult.ok((int)totalCount, list2);
    }

    @Override
    public boolean deleteAll(Integer[] ids) {
        return false;
    }


    @Override
    public boolean deleteById(Long id) {
        int count = orderMapper.deleteByPrimaryKey(id);
        return count == 1;
    }

    @Override
    public boolean add(Order order) {
        return false;
    }

    @Override
    public Order selectById(Integer id) {
        return null;
    }


    @Override
    public boolean update(Order order) {
        int count =orderMapper.updateByPrimaryKeySelective(order);
        return count==1;
    }

    @Override
    public boolean changeStatus(Integer id, Integer status) {
        return false;
    }

    @Override
    public List<OrderEchartsVO> queryEchartsData() {
        return orderMapper.queryEchartsData();
    }


}
